<?php
/* SVN FILE: $Id: app_controller.php 6305 2008-01-02 02:33:56Z phpnut $ */
/**
 * Short description for file.
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
 * Copyright 2005-2008, Cake Software Foundation, Inc.
 *								1785 E. Sahara Avenue, Suite 490-204
 *								Las Vegas, Nevada 89104
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright		Copyright 2005-2008, Cake Software Foundation, Inc.
 * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package			cake
 * @subpackage		cake.cake
 * @since			CakePHP(tm) v 0.2.9
 * @version			$Revision: 6305 $
 * @modifiedby		$LastChangedBy: phpnut $
 * @lastmodified	$Date: 2008-01-01 20:33:56 -0600 (Tue, 01 Jan 2008) $
 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
 */
/**
 * This is a placeholder class.
 * Create the same file in app/app_controller.php
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package		cake
 * @subpackage	cake.cake
 */
class AppController extends Controller {

	function checkSession($valid_profile = null) {
	//Si la informacion de sesion no ha sido definida...
		if (!$this->Session->check('User')) {
			//Fuerza al usuario a iniciar sesion
			$this->redirect('/users/login');
			exit();
		} else {	
			$usr_profile = $this->Session->read('Profile');
			//echo "up: ".$usr_profile." vp: ".$valid_profile;
			if (!is_null($valid_profile)) {
				if ($usr_profile != $valid_profile) {
					//Si el perfil no es el permitido se va afuera
					$this->redirect('/users/login');
					exit();
				}
			}
		}
	}
	
	function getBaseCodCodigo($cod_codigo) {
		if (preg_match('/^.*-MACH$/', $cod_codigo)) {
			$IS_MACH = true;
			$cod_codigo_base = preg_replace('/-MACH/', '', $cod_codigo);
		} else {
			$IS_MACH = false;
			$cod_codigo_base = $cod_codigo;
		}
		
		return $cod_codigo_base;
		
	}
}
?>